bitkeeper revision 1.1662.1.5 (42a46588UuohS0CHY1F3XZtrchaAwA)
authorcl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Mon, 6 Jun 2005 15:02:32 +0000 (15:02 +0000)
committercl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Mon, 6 Jun 2005 15:02:32 +0000 (15:02 +0000)
Many files:
  Remove device indexing.
Signed-off-by: Mike Wray <mike.wray@hp.com>
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
tools/python/xen/xend/XendDomain.py
tools/python/xen/xend/XendDomainInfo.py
tools/python/xen/xend/server/blkif.py
tools/python/xen/xend/server/console.py
tools/python/xen/xend/server/controller.py
tools/python/xen/xend/server/netif.py
tools/python/xen/xend/server/usbif.py

index c7102a6f50d24a274fba6ea2f9f1c5f8d4c6916c..eed2e7f8a3f59cc3c1db7f4777af27617c04a3e2 100644 (file)
@@ -650,13 +650,13 @@ class XendDomain:
         @return: device object (or None)
         """
         dominfo = self.domain_lookup(id)
-        return dominfo.getDeviceByIndex(type, devid)
+        return dominfo.getDevice(type, devid)
 
     def domain_vif_limit_set(self, id, vif, credit, period):
         """Limit the vif's transmission rate
         """
         dominfo = self.domain_lookup(id)
-        dev = dominfo.getDeviceById('vif', vif)
+        dev = dominfo.getDevice('vif', vif)
         if not dev:
             raise XendError("invalid vif")
         return dev.setCreditLimit(credit, period)
index 1746985ced5924d470706171e90bab3339190045..23e519abc308746236d34fe24fffc2ccbb6673bc 100644 (file)
@@ -353,7 +353,7 @@ class XendDomainInfo:
         self.controllers[type] = ctrl
         return ctrl
 
-    def createDevice(self, type, devconfig, recreate=False):
+    def createDevice(self, type, devconfig):
         ctrl = self.findDeviceController(type)
         return ctrl.createDevice(devconfig, recreate=self.recreate)
 
@@ -369,30 +369,14 @@ class XendDomainInfo:
         ctrl = self.getDeviceController(type)
         return ctrl.deleteDevice(id)
 
-    def getDevice(self, type, id):
+    def getDevice(self, type, id, error=True):
         ctrl = self.getDeviceController(type)
-        return ctrl.getDevice(id)
+        return ctrl.getDevice(id, error=error)
         
-    def getDeviceByIndex(self, type, idx):
-        ctrl = self.getDeviceController(type)
-        return ctrl.getDeviceByIndex(idx)
-
-    def getDeviceConfig(self, type, id):
-        ctrl = self.getDeviceController(type)
-        return ctrl.getDeviceConfig(id)
-
     def getDeviceIds(self, type):
         ctrl = self.getDeviceController(type)
         return ctrl.getDeviceIds()
     
-    def getDeviceIndexes(self, type):
-        ctrl = self.getDeviceController(type)
-        return ctrl.getDeviceIndexes()
-    
-    def getDeviceConfigs(self, type):
-        ctrl = self.getDeviceController(type)
-        return ctrl.getDeviceConfigs()
-
     def getDeviceSxprs(self, type):
         ctrl = self.getDeviceController(type)
         return ctrl.getDeviceSxprs()
@@ -578,24 +562,23 @@ class XendDomainInfo:
                 devices.append(dev)
         return devices
 
-    def get_device_savedinfo(self, type, index):
+    def get_device_savedinfo(self, type, id):
         val = None
         if self.savedinfo is None:
             return val
         devices = sxp.child(self.savedinfo, 'devices')
         if devices is None:
             return val
-        index = str(index)
         for d in sxp.children(devices, type):
-            dindex = sxp.child_value(d, 'index')
-            if dindex is None: continue
-            if str(dindex) == index:
+            did = sxp.child_value(d, 'id')
+            if did is None: continue
+            if int(did) == id:
                 val = d
                 break
         return val
 
-    def get_device_recreate(self, type, index):
-        return self.get_device_savedinfo(type, index) or self.recreate
+    def get_device_recreate(self, type, id):
+        return self.get_device_savedinfo(type, id) or self.recreate
 
     def add_config(self, val):
         """Add configuration data to a virtual machine.
@@ -765,7 +748,6 @@ class XendDomainInfo:
 
     def create_configured_devices(self):
         devices = sxp.children(self.config, 'device')
-        indexes = {}
         for d in devices:
             dev_config = sxp.child0(d)
             if dev_config is None:
@@ -774,13 +756,7 @@ class XendDomainInfo:
             ctrl_type = get_device_handler(dev_type)
             if ctrl_type is None:
                 raise VmError('unknown device type: ' + dev_type)
-            # Keep track of device indexes by type, so we can fish
-            # out saved info for recreation.
-            idx = indexes.get(dev_type, -1)
-            idx += 1
-            indexes[ctrl_type] = idx
-            recreate = self.get_device_recreate(dev_type, idx)
-            self.createDevice(ctrl_type, dev_config, recreate=recreate)
+            self.createDevice(ctrl_type, dev_config)
         
     def create_devices(self):
         """Create the devices for a vm.
@@ -840,16 +816,14 @@ class XendDomainInfo:
         self.config.append(['device', dev.getConfig()])
         return dev.sxpr()
 
-    def device_configure(self, dev_config, idx):
+    def device_configure(self, dev_config, id):
         """Configure an existing device.
 
         @param dev_config: device configuration
-        @param idx:  device index
+        @param id:         device id
         """
         type = sxp.name(dev_config)
-        dev = self.getDeviceByIndex(type, idx)
-        if not dev:
-            raise VmError('invalid device: %s %s' % (type, idx))
+        dev = self.getDevice(type, id)
         old_config = dev.getConfig()
         new_config = dev.configure(dev_config, change=True)
         # Patch new config into vm config.
@@ -859,26 +833,22 @@ class XendDomainInfo:
         self.config[old_index] = new_full_config
         return new_config
 
-    def device_refresh(self, type, idx):
+    def device_refresh(self, type, id):
         """Refresh a device.
 
         @param type: device type
-        @param idx:  device index
+        @param id:   device id
         """
-        dev = self.getDeviceByIndex(type, idx)
-        if not dev:
-            raise VmError('invalid device: %s %s' % (type, idx))
+        dev = self.getDevice(type, id)
         dev.refresh()
         
-    def device_delete(self, type, idx):
+    def device_delete(self, type, id):
         """Destroy and remove a device.
 
         @param type: device type
-        @param idx:  device index
+        @param id:   device id
         """
-        dev = self.getDeviceByIndex(type, idx)
-        if not dev:
-            raise VmError('invalid device: %s %s' % (type, idx))
+        dev = self.getDevice(type, id)
         dev_config = dev.getConfig()
         if dev_config:
             self.config.remove(['device', dev_config])
index 7c38dec9034bde742508dc902d4c56f373de7a73..602979fed0890b10ae02af61a8d3870713530337 100755 (executable)
@@ -293,7 +293,6 @@ class BlkDev(Dev):
             val.append(['uname', self.uname])
         if self.node:
             val.append(['node', self.node])
-        val.append(['index', self.getIndex()])
         return val
 
     def getBackend(self):
index 4f2a498aac8aceb5c2fd396150dd87c7acbede32..1d0489de7ff7fa37af5f9858842e0548103e7327 100755 (executable)
@@ -129,7 +129,6 @@ class ConsoleDev(Dev, protocol.ServerFactory):
             val.append(['local_port',   self.getLocalPort()  ])
             val.append(['remote_port',  self.getRemotePort() ])
             val.append(['console_port', self.console_port    ])
-            val.append(['index', self.getIndex()])
             if self.addr:
                 val.append(['connected', self.addr[0], self.addr[1]])
         finally:
index 0459d0b9fc1c5ba353f10df20bc2ca832df8611f..8dd85430e6702a014a5ac6979cade5a45aa22efa 100755 (executable)
@@ -228,19 +228,20 @@ class DevController:
         If change is true the device is a change to an existing domain,
         i.e. it is being added at runtime rather than when the domain is created.
         """
-        dev = self.newDevice(self.nextDeviceId(), config, recreate=recreate)
+        # skanky hack: we use the device ids to maybe find the savedinfo
+        # of the device...
+        id = self.nextDeviceId()
+        if recreate:
+            recreate = self.vm.get_device_savedinfo(self.getType(), id)
+        dev = self.newDevice(id, config, recreate=recreate)
         dev.init(recreate=recreate)
         self.addDevice(dev)
-        idx = self.getDeviceIndex(dev)
-        recreate = self.vm.get_device_recreate(self.getType(), idx)
         dev.attach(recreate=recreate, change=change)
 
     def configureDevice(self, id, config, change=False):
         """Reconfigure an existing device.
         May be defined in subclass."""
-        dev = self.getDevice(id)
-        if not dev:
-            raise XendError("invalid device id: " + id)
+        dev = self.getDevice(id, error=True)
         dev.configure(config, change=change)
 
     def destroyDevice(self, id, change=False, reboot=False):
@@ -251,9 +252,7 @@ class DevController:
 
         The device is not deleted, since it may be recreated later.
         """
-        dev = self.getDevice(id)
-        if not dev:
-            raise XendError("invalid device id: " + id)
+        dev = self.getDevice(id, error=True)
         dev.destroy(change=change, reboot=reboot)
         return dev
 
@@ -278,24 +277,15 @@ class DevController:
     def isDestroyed(self):
         return self.destroyed
 
-    def getDevice(self, id):
-        return self.devices.get(id)
-
-    def getDeviceByIndex(self, idx):
-        if 0 <= idx < len(self.device_order):
-            return self.device_order[idx]
-        else:
-            return None
-
-    def getDeviceIndex(self, dev):
-        return self.device_order.index(dev)
+    def getDevice(self, id, error=False):
+        dev = self.devices.get(id)
+        if error and not dev:
+            raise XendError("invalid device id: " + id)
+        return dev
 
     def getDeviceIds(self):
         return [ dev.getId() for dev in self.device_order ]
 
-    def getDeviceIndexes(self):
-        return range(0, len(self.device_order))
-    
     def getDevices(self):
         return self.device_order
 
@@ -380,9 +370,6 @@ class Dev:
     def getId(self):
         return self.id
 
-    def getIndex(self):
-        return self.controller.getDeviceIndex(self)
-
     def getConfig(self):
         return self.config
 
index 90e41d03da5105f4cc57ba6e96867d05bc02b718..ceb2f912a3720b796ca3f427692163f664a8840f 100755 (executable)
@@ -199,7 +199,6 @@ class NetDev(Dev):
             val.append(['evtchn',
                         self.evtchn['port1'],
                         self.evtchn['port2']])
-        val.append(['index', self.getIndex()])
         return val
 
     def get_vifname(self):
index f64ea83d4bb3007de048fdcb7e33ef4a18931332..657a98e67112d95664470231136eb601e70c0cec 100644 (file)
@@ -186,7 +186,6 @@ class UsbDev(Dev):
                ['port', self.port],
                ['path', self.path],
                ]
-        val.append(['index', self.getIndex()])
         return val
 
     def getBackend(self):